package org.budo.mongo.jdbc.driver.statement.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;

import org.budo.jdbc.driver.AbstractBudoJdbcPreparedStatement;
import org.budo.mongo.jdbc.driver.executor.MongoStatementExecutor;
import org.budo.mongo.jdbc.driver.statement.AbstractMongoStatement;
import org.budo.mongo.jdbc.driver.statement.StatementDocument;

/**
 * @author li
 */
public class MongoDeleteStatement extends AbstractMongoStatement {
    public void execute(PreparedStatement preparedStatement) throws SQLException {
        StatementDocument statementDocument = this.statementDocument(preparedStatement);

        Map<String, Object> where = statementDocument.getWhere();

        MongoStatementExecutor statementExecutor = this.statementExecutor(preparedStatement);
        Integer deletedCount = statementExecutor.delete(this.getCollectionName(), where);

        ((AbstractBudoJdbcPreparedStatement) preparedStatement).setUpdateCount(deletedCount);
    }
}